{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fe924274",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {},
       "report_default": {
        "hidden": false
       }
      }
     }
    }
   },
   "source": [
    "# python 装饰器中的 self"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "976805e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: decorator in /home/westwood/anaconda3/lib/python3.8/site-packages (5.0.6)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install decorator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "88b480e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from decorator import decorator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "add2e6b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "@decorator\n",
    "def print_class_name(func, self, *args, **kwargs):\n",
    "    print(\"my class name is\",self.__class__.__name__)\n",
    "    return func(self, *args, **kwargs)\n",
    "\n",
    "class Foo:\n",
    "    \n",
    "    @print_class_name\n",
    "    def hello_world(self, name):\n",
    "        return name + \": hello_world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1ee10d80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my class name is Foo\n",
      "jack: hello_world\n",
      "my class name is Foo\n",
      "tom: hello_world\n"
     ]
    }
   ],
   "source": [
    "foo = Foo()\n",
    "print(foo.hello_world(\"jack\"))\n",
    "print(Foo().hello_world(\"tom\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18b8af90",
   "metadata": {},
   "source": [
    "# python 中的 site-package 和 dist-package"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bc913e4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/mnt/c/Users/20210817/Desktop/代码训练_2022/source/code/第6周',\n",
       " '/home/westwood/anaconda3/lib/python38.zip',\n",
       " '/home/westwood/anaconda3/lib/python3.8',\n",
       " '/home/westwood/anaconda3/lib/python3.8/lib-dynload',\n",
       " '',\n",
       " '/home/westwood/anaconda3/lib/python3.8/site-packages',\n",
       " '/home/westwood/anaconda3/lib/python3.8/site-packages/locket-0.2.1-py3.8.egg',\n",
       " '/home/westwood/anaconda3/lib/python3.8/site-packages/IPython/extensions',\n",
       " '/home/westwood/.ipython']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "sys.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5b941a1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sys.path = [\r\n",
      "    '/mnt/c/Users/20210817/Desktop/代码训练_2022/source/code/第6周',\r\n",
      "    '/home/westwood/anaconda3/lib/python38.zip',\r\n",
      "    '/home/westwood/anaconda3/lib/python3.8',\r\n",
      "    '/home/westwood/anaconda3/lib/python3.8/lib-dynload',\r\n",
      "    '/home/westwood/anaconda3/lib/python3.8/site-packages',\r\n",
      "    '/home/westwood/anaconda3/lib/python3.8/site-packages/locket-0.2.1-py3.8.egg',\r\n",
      "]\r\n",
      "USER_BASE: '/home/westwood/.local' (exists)\r\n",
      "USER_SITE: '/home/westwood/.local/lib/python3.8/site-packages' (doesn't exist)\r\n",
      "ENABLE_USER_SITE: True\r\n"
     ]
    }
   ],
   "source": [
    "!python -m site"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56958a11",
   "metadata": {},
   "source": [
    "# Jupyter Tidbit: IPython's ! returns an SList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7e3ac94b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['my_module', '第6周的配套代码.ipynb']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = !ls\n",
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f9ca4a2",
   "metadata": {},
   "source": [
    "# Jupyter Tidbit: Display handles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d9af887c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import itertools\n",
    "import time\n",
    "\n",
    "from IPython.display import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "75e50cc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "## &#128591; 0x1f64f"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "## &#128591; 0x1f64f"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "## &#128591; 0x1f64f"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "## &#128591; 0x1f64f"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dh_1 = display(display_id=\"1\")\n",
    "dh_1.display(\"\")\n",
    "dh_2 = display(display_id=\"2\")\n",
    "dh_2.display(\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "df36fcce",
   "metadata": {},
   "outputs": [],
   "source": [
    "dh_2.update(\"ddd\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "773f18cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in (range(0x1F600, 0x1F650)):\n",
    "    dh_1.update(Markdown(f'## &#{i}; {hex(i)}'))\n",
    "    time.sleep(0.01)\n",
    "    dh_2.update(Markdown(f'## &#{i}; {hex(i)}'))"
   ]
  }
 ],
 "metadata": {
  "extensions": {
   "jupyter_dashboards": {
    "activeView": "report_default",
    "version": 1,
    "views": {
     "grid_default": {
      "cellMargin": 10,
      "defaultCellHeight": 20,
      "maxColumns": 12,
      "name": "grid",
      "type": "grid"
     },
     "report_default": {
      "name": "report",
      "type": "report"
     }
    }
   }
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
